package com.mit.wx.service.impl;

import com.mit.wx.dao.AutoReplyRuleDao;
import com.mit.wx.dao.BaseDao;
import com.mit.wx.entity.AutoReplyRule;
import com.mit.wx.service.AutoReplyRuleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 2018/10/12 Create by 郭文梁
 * AutoReplyRuleServiceImpl
 * 自动回复规则组件实现
 *
 * @author 郭文梁
 * @date 2018/10/12
 */
@Service
public class AutoReplyRuleServiceImpl extends BaseServiceImpl<AutoReplyRule> implements AutoReplyRuleService {
    private final AutoReplyRuleDao autoReplyRuleDao;

    @Autowired
    public AutoReplyRuleServiceImpl(AutoReplyRuleDao autoReplyRuleDao) {
        this.autoReplyRuleDao = autoReplyRuleDao;
    }

    @Override
    public BaseDao<AutoReplyRule> getRepository() {
        return autoReplyRuleDao;
    }

    @Override
    public AutoReplyRule findMatchingRule(String msg) {
        List<AutoReplyRule> rules = autoReplyRuleDao.findByMsgAndRule(msg, AutoReplyRule.RULE_MATCHING);
        return rules == null || rules.size() <= 0 ? null : rules.get(0);
    }

    @Override
    public AutoReplyRule findContainRule(String msg) {
        List<AutoReplyRule> rules = autoReplyRuleDao.findByMsgLikeAndRule(msg, AutoReplyRule.RULE_CONTAIN);
        return rules == null || rules.size() <= 0 ? null : rules.get(0);
    }
}
